package com.chujian.framework.core.tsdata;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据传输基类
 *
 * @param <T> 泛型payload
 */
public class TsData<T> implements ITsData<T> {

    private Serializable dataMark;
    private Serializable dataId;
    private TsDataMeta meta = new TsDataMeta();
    private T payload;
    private Map<String, Object> extMap = new HashMap<>();
    private Long creTime;
    private Long acId;

    @Override
    public Serializable getDataMark() {
        return this.dataMark;
    }

    @Override
    public ITsData<T> setDataMark(Serializable dataMark) {
        this.dataMark = dataMark;
        return this;
    }

    @Override
    public Serializable getDataId() {
        return this.dataId;
    }

    @Override
    public ITsData<T> setDataId(Serializable dataId) {
        this.dataId = dataId;
        return this;
    }

    @Override
    public TsDataMeta getMeta() {
        return this.meta;
    }

    @Override
    public ITsData<T> setMeta(TsDataMeta meta) {
        this.meta = meta;
        return this;
    }

    @Override
    public Object getMeta(String key) {
        if (null == this.meta) {
            return null;
        }
        return this.meta.get(key);
    }

    @Override
    public ITsData<T> addMeta(String key, Object obj) {
        this.meta.add(key, obj);
        return this;
    }

    @Override
    public T getPayload() {
        return this.payload;
    }

    @Override
    public ITsData<T> setPayload(T payload) {
        this.payload = payload;
        return this;
    }

    @Override
    public Map<String, Object> getExtInfo() {
        return this.extMap;
    }

    @Override
    public ITsData<T> setExtInfo(Map<String, Object> extInfo) {
        this.extMap = extInfo;
        return this;
    }

    @Override
    public Object getExt(String key) {
        return extMap.get(key);
    }

    @Override
    public ITsData<T> addExt(String key, Object obj) {
        extMap.put(key, obj);
        return this;
    }

    @Override
    public ITsData<T> removeExt(String key) {
        extMap.remove(key);
        return this;
    }

    @Override
    public Long getCreTime() {
        return creTime;
    }

    @Override
    public ITsData<T> setCreTime(Long creTime) {
        this.creTime = creTime;
        return this;
    }

    @Override
    public Long getAcId() {
        return this.acId;
    }

    @Override
    public ITsData<T> setAcId(Long acId) {
        this.acId = acId;
        return this;
    }
}
